package leetcode;

import java.util.HashSet;

public class thirdteen {
    //https://leetcode.cn/problems/fruit-into-baskets/
    public static int totalFruit(int[] fruits) {
        int n=fruits.length;
        int max=0;
        for(int i=0;i<n;i++){
            HashSet<Integer> set=new HashSet<>();
            for(int j=i;j<n;j++){
                if(set.size()<2||set.contains(fruits[j])){
                    set.add(fruits[j]);
                    max=Math.max(max,j-i+1);
                }else{
                    break;
                }
            }
        }
        return max;


    }

    public static void main(String[] args) {
        int[] array={1,2,3,2,2};
        int i = totalFruit(array);
        System.out.println(i);
    }
}
